/**
 *
 */
package urban;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedSet;

import javax.xml.stream.XMLStreamException;

import org.jdom.JDOMException;

/**
 * @author emily
 *
 */
public class Main {

	/**
	 * @param args
	 * @throws XMLStreamException
	 * @throws IOException
	 * @throws JDOMException
	 */
	public static void main(String[] args) throws XMLStreamException, JDOMException, IOException {

		// Initialize results object and enter it in the database
		Result<Sentence> results = new Result<Sentence>(null);
		results.store();
		
		// Start timer.
//		long start = System.currentTimeMillis();

		String[] letterArray = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
				"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
				"W", "X", "Y", "Z" };

//		String[] letterArray = { "A" };

		ArrayList<Letter> letters = new ArrayList<Letter>();

		int i = 0;
		for(String c : letterArray) {
			i++;
			Letter l = new Letter(c);
//			l.store();
			letters.add(l);
//			if((i%100) == 0) {
//				try {
//					Thread.sleep(2000);
//				} catch (InterruptedException e) {
//					System.out.println("Failed to sleep");
//				}
//			}
		}
		try {
			Thread.sleep(180000);
		} catch (InterruptedException e) {
			System.err.println("Could not wait");
		}


//		String[] lArray = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
//				"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
//				"W", "X", "Y", "Z" };
		
		Search s = new Search(letters, letterArray);

		SortedSet<Sentence> set = s.getTopSentences();
		Iterator<Sentence> it = set.iterator();
		while(it.hasNext()) {
			if(it.next().getNumUrbanWord() == 0) break;
			System.out.println(it.next());
		}

		/** This is meant to print out everything.
		 *  The Letter class stores the Word classes which store the
		 *  Sentence classes. I don't have the getters and setters for
		 *  the sentences yet. You should just be able to store the Letter
		 *  classes in general I think. Can you just store the letters array
		 *  that is in this class? Would that be the easiest? I'm not sure
		 *  how db4o works so just let me know if you need things switched around.
		 */

//		for(Word s : w) {
//			System.out.println(s);
//			ArrayList<Sentence> sent = s.getArrayList();
//			for(Sentence se : sent) {
//				System.out.print(se+" ");
//			}
//		}
//		System.out.println("Total Words: "+w.size());
//
//		// Print timer.
//		long finish = System.currentTimeMillis();
//		System.out.println("Total Time: "+(finish-start));
	}

}
